import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import matplotlib

matplotlib.use('TkAgg')
#from matplotlib import animation
import cv2 as cv
import paddlehub as hub
from PIL import Image, ImageSequence, ImageDraw,ImageFont
# from IPython.display import display, HTML
import numpy as np
import imageio
import os

print(hub.__version__)

pwddir=os.path.dirname(__file__)
# 测试图片路径和输出路径
test_path = os.path.join(pwddir,'image','test')
output_path = os.path.join(pwddir,'image','outpath')
print('output_path:',output_path)
# 待预测图片
test_img_path=[]
for i in os.listdir(test_path):
    test_img_path.append(os.path.join(test_path,i))
print(test_img_path)

#img = mpimg.imread(test_img_path[0])
# img=cv.imread(test_img_path[0])
# cv.imshow('img',img)
# cv.waitKey()
# cv.destroyAllWindows()
# 展示待预测图片
# plt.figure(figsize=(10,10))
# plt.imshow(img)
# plt.axis('off')
# plt.show()


module = hub.Module(name="deeplabv3p_xception65_humanseg")
# input_dict = {"image": test_img_path}
input_dict = {"image": [test_img_path[0]]}
print(input_dict)
#
# # execute predict and print the result
out_path=r'F:\PycharmOut\CGAI\AIroto\image\outpath'
results = module.segmentation(data=input_dict,output_dir=out_path)
#
# for result in results:
#     print(result)


#
# # 预测结果展示
# out_img_path = 'humanseg_output/' + os.path.basename(test_img_path[0]).split('.')[0] + '.png'
# img = mpimg.imread(out_img_path)
# plt.figure(figsize=(10,10))
# plt.imshow(img)
# plt.axis('off')
# plt.show()
# img=
# cv.imshow('img',img)
# cv.waitKey()
# cv.destroyAllWindows()